
 ;
 ;                  A C K E R M A N 's    F U N C T I O N  
 ;                                                         
 ;                              ( L I S P )                
 ;
 ;
 ;   ACKERMAN's Function is as follows :
 ;
 ;   Proc Acker ( M , N )
 ;    begin
 ;      if ( M = 0 ) and ( N <> 0 )
 ;        result = N + 1
 ;      else
 ;        if ( N = 0 ) and ( M <> 0 )
 ;          result = Acker ( M - 1 , 1 )
 ;        else
 ;          result = Acker ( M - 1 , Acker ( M , N - 1 ) )
 ;    end
 ;

 ( define ACKER
   ( begin

     ( set-video-mode! 3)

     ( define res 0 )

     ( window-set-cursor! 'console 3 20 )
     ( display "  A C K E R M A N 's    F U N C T I O N  " 'console )
     ( window-set-cursor! 'console 4 20 )

     ( display "            ( IN    L I S P )            " 'console )


     ( window-set-cursor! 'console 14 20 )
     ( display "        Enter value for M : " 'console )
     ( define m ( read ) )


     ( window-set-cursor! 'console 16 20 )
     ( display "        Enter value for N : " 'console )
     ( define n ( read ) )

     ( window-set-cursor! 'console 18 20 )
     ( display "        Result is         : " 'console )

     ( set! res ( ACKERMAN m n ) )
     ( write res )

     ( window-set-cursor! 'console 22 0 )
    )
  )

 ( define ACKERMAN
   ( lambda ( m n )
     ( if ( and ( = m 0 ) ( > n 0 ) )
         ( + n 1 )
       ( begin
         ( if ( and ( = n 0 ) ( > m 0 ) )
             ( ACKERMAN ( - m 1 ) 1 )
           ( begin
             ( ACKERMAN ( - m 1 ) ( ACKERMAN m ( - n 1 ) ) )
            )
          )
        )
      )
    )
  )
